export const CONTENT_TYPE = {
  json: 'application/json;charset=utf-8',
  urlencoded: 'application/x-www-form-urlencoded;charset=utf-8'
};

const defaultHeaderProps = {
  'Content-Type': CONTENT_TYPE.urlencoded
};

/** 解析response的headers信息
 * @function processHeaders
 * @memberOf fe-lib.FetchRequest
 * @inner
 * @param headers
 * @returns {*}
 */
export default (headers) => {
  const finalHeaders = Object.assign({}, defaultHeaderProps, headers);

  Object.keys(finalHeaders).forEach((key) => {
    if (typeof finalHeaders[key] === 'object') {
      finalHeaders[key] = JSON.stringify(finalHeaders[key]);
    }
  });

  return finalHeaders;
};
